package com.maserb.monitor.repository.schoolStudent;

import com.maserb.monitor.entity.card.AttendanceRecordEntity;
import com.maserb.monitor.entity.schoolStudent.SchoolStudentEntity;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface AttendanceRecordRepository extends JpaSpecificationExecutor<AttendanceRecordEntity>
        , PagingAndSortingRepository<AttendanceRecordEntity, String> {

    @Query(value = "select count(distinct student) from AttendanceRecordEntity where student.orgId=?1 and startTime like ?2")
    Integer countByClazzAndDate(String clazzId, String date);

    @Query(value = "from AttendanceRecordEntity where student.id=?1 and startTime like ?2")
    List<AttendanceRecordEntity> findByStudentIdAndDate(String studentId, String date);

    @Query(value = "from AttendanceRecordEntity where student.id=?1 ")
    List<AttendanceRecordEntity> findByStudentId(String studentId);

    @Query(value = "select distinct(s) from AttendanceRecordEntity r left join r.student s where s.orgId=?1 and r.startTime like ?2")
    List<SchoolStudentEntity> findStudentByClazzAndDate(String clazzId, String date);
}